package secondary

import "sort"

type Node struct {
	Left  *Node
	Right *Node
	Val   int
}
type TreeNode struct {
	Left  *TreeNode
	Right *TreeNode
	Val   int
}
func TreeConstructor(nums []int) *Node {
	sort.Ints(nums)
	return constructor(nums, 0, len(nums)-1)
}

func constructor(nums []int, l, r int) *Node {
	if l > r {
		return nil
	}
	mid := (l + r) / 2
	return &Node{
		Left:  constructor(nums, l, mid-1),
		Right: constructor(nums, mid+1, r),
		Val:   nums[mid],
	}
}
